import Vue from 'vue'
import Vuex from 'vuex'
import home from './modules/home'

Vue.use(Vuex)

const store = () =>
  new Vuex.Store({
    modules: {
      home
    },
    actions: {
      async nuxtServerInit({ commit }, { req, app }) {
        const {
          status,
          data: { data }
        } = await app.$axios.get('/shop/foodClassify')
        commit('home/setFoodClassify', status === 200 ? data : [])
        const {
          status: status2,
          data: { shop }
        } = await app.$axios.get('/shop/shopList')
        commit('home/setShopList', status2 === 200 ? shop : [])
      }
    }
  })

export default store
